package com.example.demo.PostProcessorAnalyze;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author : 叶荻风
 * @create : 2024/5/23 11:22
 */
public class ProxyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        InvocationHandler invocationHandler = (proxy, method, args) -> {
            System.out.println("dadadadasdsa");
            Object invoke = method.invoke(bean, args);
            return invoke;
        };

        return Proxy.newProxyInstance(ProxyBeanPostProcessor.class.getClassLoader(),bean.getClass().getInterfaces(),
                invocationHandler);

    }
}
